﻿''' <summary>
''' Customize form for SearchLookupEdit
''' http://www.devexpress.com/Support/Center/Question/Details/Q320852
''' </summary>
''' <remarks></remarks>
Public Class MetaPopUpSearchLookupEdit
    Inherits Popup.PopupSearchLookUpEditForm

    Private baseOwnerEdit As MetaSearchLookUpEdit
    Private baseOwnerEdit2 As MetaRepositoryItemSearchEdit

    Private _reloadButton As SimpleButton

    Public Sub New(ByVal ownerEdit As MetaSearchLookUpEdit)
        MyBase.New(ownerEdit)
        baseOwnerEdit = ownerEdit
    End Sub

    Public Sub New(ByVal ownerEdit As MetaRepositoryItemSearchEdit)
        MyBase.New(ownerEdit)
        baseOwnerEdit2 = ownerEdit
    End Sub

    ''' <summary>
    ''' Default constructor From SearchLookUpEdit
    ''' </summary>
    ''' <param name="ownerEdit"></param>
    ''' <remarks></remarks>
    Public Sub New(ByVal ownerEdit As SearchLookUpEdit)
        MyBase.New(ownerEdit)
    End Sub

    Public Property ReloadButton() As SimpleButton
        Get
            If _reloadButton Is Nothing Then
                _reloadButton = New SimpleButton()
                _reloadButton.Parent = Me
                _reloadButton.Text = "Reload"
                AddHandler _reloadButton.Click, AddressOf ReloadClick
            End If
            Return _reloadButton
        End Get
        Set(ByVal value As SimpleButton)
            _reloadButton = value
        End Set
    End Property

    Private Sub ReloadClick(ByVal sender As Object, ByVal e As System.EventArgs)
        If baseOwnerEdit IsNot Nothing Then
            baseOwnerEdit.Properties.DataSource = Nothing
            baseOwnerEdit.InitMetaQuery()
            baseOwnerEdit.ShowPopup()
        End If
        If baseOwnerEdit2 IsNot Nothing Then
            'baseOwnerEdit2.Properties.DataSource = Nothing
            'baseOwnerEdit2.Properties.InitMetaQuery(baseOwnerEdit2.Properties.QueryName)
            'baseOwnerEdit2.ShowPopup()
        End If
    End Sub

    Protected Overrides Sub SetupButtons()
        MyBase.SetupButtons()
        'ReloadButton.Left = Width - 200
        'ReloadButton.Top = Height - 85
        'ReloadButton.Width = 75
        'ReloadButton.Height = 22
        'ReloadButton.Visible = True
        'ReloadButton.BringToFront()
        'ReloadButton.Anchor = (AnchorStyles.Bottom Or AnchorStyles.Right)
    End Sub

    Protected Overrides Sub Dispose(disposing As Boolean)
        MyBase.Dispose(disposing)
        If _reloadButton IsNot Nothing Then
            RemoveHandler _reloadButton.Click, AddressOf ReloadClick
            _reloadButton.Dispose()
        End If
    End Sub
End Class
